import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
// 懒加载
const view = name => () => import('@/views/' + name)

/*
 *meta: {
 *          parentName: 跳转路由的name值,
 *          title: tabs菜单显示名称，如设置front，admin 此选项必填,
 *          front: true, // 前台需要生成的菜单
 *          admin: true // 后台需要生成的菜单
 *          keepAlive: true // 缓存设置true，否则则不用设置
 *          common: true // 公用路由设置，动态设置菜单选中状态
 *          hasCommon: true // 需要用到公用路由的路由需设置
 *       },
 */

export default new Router({
  mode: 'hash',
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  },
  routes: [{
    path: '/',
    redirect: '/map'
  },
  {
    path: '/login',
    name: 'login',
    component: view('login')
  },
  {
    path: '/frames',
    name: 'frames',
    component: view('frames/index'),
    children: [
      {
        path: '/map',
        name: 'map',
        component: view('map/index')
      },
      {
        path: '/bzzy',
        name: 'bzzy',
        component: view('bzzy/index')
      },
      {
        path: '/zzbz',
        name: 'zzbz',
        component: view('zzbz/index')
      },
      {
        path: '/bdfx',
        name: 'bdfx',
        component: view('bdfx/index')
      },
      {
        path: '/earlywarning',
        name: 'earlywarning',
        component: view('earlywarning/index')
      },
      {
        path: '/ywfx',
        name: 'ywfx',
        component: view('ywfx/index')
      }
    ]
  },
  // 后台
  {
    path: '/adminMain',
    name: 'adminMain',
    component: view('adminMain'),
    redirect: '/home/index',
    children: [
      {
        path: '/log/index',
        name: 'log',
        meta: {
          title: '日志',
          admin: true
        },
        component: view('log/index')
      }
    ]
  },
  {
    path: '/404',
    name: '404',
    component: view('page/404')
  },
  {
    path: '*',
    redirect: {
      name: '404'
    }
  }
  ]
})
